package com.gosling.cloudspace.tools;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 驼峰 下划线 互换
 *
 * @author lihonglin
 * @date 2022/5/27 10:56
 */
public class CaseTool {
    /**
     * 驼峰转下划线
     *
     * @param str 目标字符串
     * @return: java.lang.String
     */
    public static String humpToUnderline(String str) {
        String regex = "([A-Z])";
        Matcher matcher = Pattern.compile(regex).matcher(str);
        while (matcher.find()) {
            String target = matcher.group();
            str = str.replaceAll(target, "_" + target.toLowerCase());
        }
        return str.toUpperCase();
    }
}